﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using GameEngine.SceneGraph;

//--shotgun
namespace Redland2
{
    public class Shotgun : Gun
    {
        #region members
        private const float ACCURACY = 0.3F;
        public int numberOfShots;

        #endregion members

        #region properties
        #endregion properties

        #region constructors

        public Shotgun(GameScene inputScene, int inputIndex, Player inputOwner, Vector2 position ): base( inputScene, inputIndex, inputOwner, position )
        {
            SetupGun();
        }

        private void SetupGun()
        {
            this.FireDelay = 666;
            this.Accuracy = ACCURACY;
            this.Damage = 5;
            this.numberOfShots = 7;
        }

        #endregion constructors

        #region methods

        public override void Fire()
        {
            if (scene._time.Subtract(TimeSpan.FromMilliseconds(FireDelay)) > LastShot && this.IsAlive())
            {
                LastShot = scene._time;
                Vector2 offsetPosition = this.Position;
                offsetPosition += Vector2.Transform(Direction, Matrix.CreateRotationZ(MathHelper.PiOver2)) * 4; // offset bullet to the right of center of player
                offsetPosition += Direction * this.TextureWidth; // offset bullet to tip of barrel
                Vector2 shotDirection = Owner.TargetPos - offsetPosition;
                shotDirection.Normalize();
                shotDirection *= 500;
                for (int i = 0; i < numberOfShots; i++)
                {
                    Vector2 individualDirection = shotDirection + new Vector2(rand.Next() % 200 - 100, rand.Next() % 200 - 100) * (1 - Accuracy) ;
                    scene._entities.Add(new Bullet(this.scene, this.scene._entities.Count, Owner, offsetPosition, individualDirection, base.Damage));
                }
            }
            //base.Fire();
        }
        #endregion methods 
    }
}
